##! /bin/bash
#! bash
#
#  $Id: to_article.sh 3 2010-05-27 16:25:49Z alistair.mills@btinternet.com $
#

### Main script stars here ###
# Store file name  here
export       FILE=$1
export     OUTPUT=$2
export    OUTPUT2=$3
export   LANGUAGE=$4
export      total=0
. ./defines.sh
. ./keys.sh
touch   $OUTPUT $OUTPUT2
rm      $OUTPUT $OUTPUT2
while read year mon cat words url key trans line
do
  if [ "$line" != "$title_line" -a "$year" != "$comment_line" ]
  then
                                  export INPUT=${year}_${mon}_${cat}.txt
    [ "$LANGUAGE" = "french" ] && export INPUT=${year}_${mon}_${cat}_fr.txt
    if [ "$line" != ""  -a -f $INPUT ]
    then
      export       total=`expr $total + 1`
      export         tot=`printf '%.3i' $total`
      echo Found $key: $tot - $INPUT - $line
      export      output=""
      export change_date=`cat $last$INPUT`
      export   ArticleID=$total
      export          yr=$year
      export   file_date="$change_date"
      #echo cat=$cat
      #echo mon=$mon
      #echo change_date=$change_date
      #export xxx=xxx
      echo "insert into  \`tblArticle\` (\`ArticleID\`,  \`yr\`, \`mon\`, \`cat\`,   \`trans\`, \`words\`,  \`url\`,   \`file_date\`,  \`language\`,  \`title\`,  \`key\` )   \
                                  values ($ArticleID,     $yr,    $mon,  \"$cat\",  \"$trans\",  $words,   \"$url\",  \"$file_date\", \"$language\", \"$line\",  \"$key\" );" >> $OUTPUT
      echo                               "$ArticleID;$yr;\"$mon\";\"$cat\";\"$trans\";$words;\"$url\";\"$file_date\";\"$language\";\"$line\";\"$key\""   >> $OUTPUT2
    fi
  fi
done < $FILE
#
#
#
